package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.AdressesTiers;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage AdressesTiers entities.
 * 
 */
@Repository("AdressesTiersDAO")
@Transactional
public class AdressesTiersDAOImpl extends AbstractJpaDao<AdressesTiers>
		implements AdressesTiersDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { AdressesTiers.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new AdressesTiersDAOImpl
	 *
	 */
	public AdressesTiersDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreation
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreation(java.util.Calendar adtDateCreation) throws DataAccessException {

		return findAdressesTiersByAdtDateCreation(adtDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreation(java.util.Calendar adtDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateCreation", startResult, maxRows, adtDateCreation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreationBefore
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreationBefore(java.util.Calendar adtDateCreation) throws DataAccessException {

		return findAdressesTiersByAdtDateCreationBefore(adtDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreationBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreationBefore(java.util.Calendar adtDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateCreationBefore", startResult, maxRows, adtDateCreation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTypeAdresseContaining
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTypeAdresseContaining(String adtTypeAdresse) throws DataAccessException {

		return findAdressesTiersByAdtTypeAdresseContaining(adtTypeAdresse, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTypeAdresseContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTypeAdresseContaining(String adtTypeAdresse, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtTypeAdresseContaining", startResult, maxRows, adtTypeAdresse);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectation
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectation(java.util.Calendar adtFinAffectation) throws DataAccessException {

		return findAdressesTiersByAdtFinAffectation(adtFinAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectation(java.util.Calendar adtFinAffectation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtFinAffectation", startResult, maxRows, adtFinAffectation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreationAfter
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreationAfter(java.util.Calendar adtDateCreation) throws DataAccessException {

		return findAdressesTiersByAdtDateCreationAfter(adtDateCreation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateCreationAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateCreationAfter(java.util.Calendar adtDateCreation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateCreationAfter", startResult, maxRows, adtDateCreation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtAdresse
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtAdresse(Integer adtAdresse) throws DataAccessException {

		return findAdressesTiersByAdtAdresse(adtAdresse, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtAdresse
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtAdresse(Integer adtAdresse, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtAdresse", startResult, maxRows, adtAdresse);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModification
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModification(java.util.Calendar adtDateModification) throws DataAccessException {

		return findAdressesTiersByAdtDateModification(adtDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModification
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModification(java.util.Calendar adtDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateModification", startResult, maxRows, adtDateModification);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModificationAfter
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModificationAfter(java.util.Calendar adtDateModification) throws DataAccessException {

		return findAdressesTiersByAdtDateModificationAfter(adtDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModificationAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModificationAfter(java.util.Calendar adtDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateModificationAfter", startResult, maxRows, adtDateModification);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTypeAdresse
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTypeAdresse(String adtTypeAdresse) throws DataAccessException {

		return findAdressesTiersByAdtTypeAdresse(adtTypeAdresse, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTypeAdresse
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTypeAdresse(String adtTypeAdresse, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtTypeAdresse", startResult, maxRows, adtTypeAdresse);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtEtatAffectation
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtEtatAffectation(String adtEtatAffectation) throws DataAccessException {

		return findAdressesTiersByAdtEtatAffectation(adtEtatAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtEtatAffectation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtEtatAffectation(String adtEtatAffectation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtEtatAffectation", startResult, maxRows, adtEtatAffectation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByPrimaryKey
	 *
	 */
	@Transactional
	public AdressesTiers findAdressesTiersByPrimaryKey(Integer adtAdresse, Integer adtTiers, String adtTypeAdresse, String adtEtatAffectation, java.util.Calendar adtFinAffectation) throws DataAccessException {

		return findAdressesTiersByPrimaryKey(adtAdresse, adtTiers, adtTypeAdresse, adtEtatAffectation, adtFinAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByPrimaryKey
	 *
	 */

	@Transactional
	public AdressesTiers findAdressesTiersByPrimaryKey(Integer adtAdresse, Integer adtTiers, String adtTypeAdresse, String adtEtatAffectation, java.util.Calendar adtFinAffectation, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findAdressesTiersByPrimaryKey", adtAdresse, adtTiers, adtTypeAdresse, adtEtatAffectation, adtFinAffectation);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtEtatAffectationContaining
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtEtatAffectationContaining(String adtEtatAffectation) throws DataAccessException {

		return findAdressesTiersByAdtEtatAffectationContaining(adtEtatAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtEtatAffectationContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtEtatAffectationContaining(String adtEtatAffectation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtEtatAffectationContaining", startResult, maxRows, adtEtatAffectation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTiers
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTiers(Integer adtTiers) throws DataAccessException {

		return findAdressesTiersByAdtTiers(adtTiers, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtTiers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtTiers(Integer adtTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtTiers", startResult, maxRows, adtTiers);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectationBefore
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectationBefore(java.util.Calendar adtFinAffectation) throws DataAccessException {

		return findAdressesTiersByAdtFinAffectationBefore(adtFinAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectationBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectationBefore(java.util.Calendar adtFinAffectation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtFinAffectationBefore", startResult, maxRows, adtFinAffectation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectationAfter
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectationAfter(java.util.Calendar adtFinAffectation) throws DataAccessException {

		return findAdressesTiersByAdtFinAffectationAfter(adtFinAffectation, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtFinAffectationAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtFinAffectationAfter(java.util.Calendar adtFinAffectation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtFinAffectationAfter", startResult, maxRows, adtFinAffectation);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllAdressesTierss
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAllAdressesTierss() throws DataAccessException {

		return findAllAdressesTierss(-1, -1);
	}

	/**
	 * JPQL Query - findAllAdressesTierss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAllAdressesTierss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllAdressesTierss", startResult, maxRows);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModificationBefore
	 *
	 */
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModificationBefore(java.util.Calendar adtDateModification) throws DataAccessException {

		return findAdressesTiersByAdtDateModificationBefore(adtDateModification, -1, -1);
	}

	/**
	 * JPQL Query - findAdressesTiersByAdtDateModificationBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<AdressesTiers> findAdressesTiersByAdtDateModificationBefore(java.util.Calendar adtDateModification, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAdressesTiersByAdtDateModificationBefore", startResult, maxRows, adtDateModification);
		return new LinkedHashSet<AdressesTiers>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(AdressesTiers entity) {
		return true;
	}
}
